#include <vector>
#include <unordered_set>
#include <string>

using std::vector;
using std::unordered_set;
using std::string;

class Solution {
public:
    vector<string> summaryRanges(vector<int>& nums) {
        vector<string> ret;
        int index = 0;
        while (index < nums.size()) {
            int first = nums[index];
            int end = first;
            while (++index < nums.size() && nums[index] == end + 1) {
                end = nums[index];
            }
            if (first == end) {
                ret.push_back(std::to_string(first));
            }
            else {
                ret.push_back(std::to_string(first) + "->" + std::to_string(end));
            }
        }
        return ret;
    }
};